﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Bidder_RemoteDecComptete : System.Web.UI.Page
{
    string RDPPwd, RDPRPrice;
    Int32 RDPProjectId;
    public String strConditions;
    string Account_RDPTBR;
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {

            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {
                Label3.Visible = false;
                String SQL;
                RDPProjectId = SysFun.ToInt(SysFun.IsSQL(Request.QueryString["ProjectId"]));
                Account_RDPTBR = SysFun.ToTrim(_Account.AccountId);
                Db db = new Db();
                System.Data.IDataReader dr;
                SQL = "Select BidSuccess,memo1 From ProjectCompanyAttribution Where BidSuccess='1' and  memo1='1' and  accountid =" + Account_RDPTBR + " and projectid = " + RDPProjectId;
                dr = db.DataReader(SQL);
                if (dr.Read())
                {
                    showGridView();
                    this.Label1.Visible = false;
                    this.Label2.Visible = false;
                    this.PricePassword.Visible = false;
                    this.RetinuePassword.Visible = false;
                    Button1.Visible = false;
                    GridView1.Visible = true;
                    Label3.Visible = true;

                }
                dr.Close();
                dr.Dispose();
                db.Close();
            }

        }
    }
    /// <summary>
    /// 报价解密
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {

        string strSql;
        RDPPwd = PricePassword.Text.Trim();
        RDPRPrice = RetinuePassword.Text.Trim();
        int number = 0;


        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            Account_RDPTBR = SysFun.ToTrim(_Account.AccountId);
            if (PricePassword.Text.Trim() == "" || RetinuePassword.Text.Trim() == "")
            {
                Response.Write("<script language=JavaScript>alert('请填写密码');</script>");
            }
            else
            {

                Db db = new Db();
                System.Data.IDataReader dr;
                strSql = "select count(*) as cun from ProjectCompanyAttribution where memo3='1' and  projectid=" + RDPProjectId;//memo3竞价解密开关

                dr = db.DataReader(strSql);
                while (dr.Read())
                {
                    if (SysFun.ToInt(dr["cun"]) == 0)
                    {
                        Response.Write("<script language=javascript>alert('竞价解密开关未开启')</script>");
                        dr.Close();
                        dr.Dispose();
                        db.Close();
                        return;
                    }

                }
                dr.Close();
                dr.Dispose();

                strSql = "select count(*) as cun from CompeteCheck where CompetePassword='" + RDPPwd + "' and CompeteRetinuePassword='" + RDPRPrice + "' and projectid = " + RDPProjectId + " and accountid=" + Account_RDPTBR;
                dr = db.DataReader(strSql);
                while (dr.Read())
                {
                    number = Convert.ToInt32(dr["cun"].ToString());
                }
                dr.Close();
                dr.Dispose();

                if (number == 0)
                {
                    Response.Write("<script language=javaScript>alert('密码错误!');</script>");
                }
                else
                {
                    strSql = "update ProjectCompanyAttribution set memo1='1',CompeteBidDate=getdate()  where accountid =" + Account_RDPTBR + " and projectid = " + RDPProjectId;//竞价解密成功
                    db.Command(strSql);

                    if (Config.EnableEncrypt)
                    {
                        DecryptByAccount.DecByAccount(_Account.AccountId.ToString());
                    } // Add By Zeus2
                    // HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "ProjectCompanyAttribution", strSql, "../Bidder/RemoteDecComptete.aspx");

                    Response.Write("<script language=javascript>alert('解密成功')</script>");
                    showGridView();


                }
                Button1.Dispose();
                db.Close();



            }
        }


    }
    /// <summary>
    /// 查询总共有多少页
    /// </summary>
    /// <returns></returns>
    /// <summary>
    /// 将数据绑定到GridView1
    /// </summary>
    /// <param name="PageIndex">转向第几页</param>
    public void showGridView()
    {
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "ComPeteTablevs";                                               //要查询的表明
        dbPage.Key = "Bidid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "BidId,goodsid,ProductName,Medicinemodel,Outlookc,Unit,GoodsName,CompanyName,factor,competeminprice,competepackprice,case ComPeteTablevs.QualityLevels when 0 then '普通GMP药品' when 1 then '专利药品' when 2 then '1999年以来获得国家科学技术奖的药品' when 3 then '国家一类新药' when 4 then '原研制药品' when 5 then '单独定价药品' when 6 then '优质优价中成药' when 7 then '全国医药工业百强企业的药品' when 8 then '中药保护品种' when 9 then '欧美认证药品' END as QualityLevels ";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //显示记录条数   
        dbPage.OrderBy = "ProductName,Medicinemodel,Outlookc,BidId";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }


    public string fctConditions()
    {
        string strtemp;
        strtemp = "projectid=" + RDPProjectId.ToString() + " and AccountId=" + Account_RDPTBR + " and";
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }

        return strtemp;

    }
}
